package com.cqhfan.chatroom.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author 眭传洪
 * @create 2024-11-19 20:13
 */
@Getter
public enum MessageType {
    CONNECTION(0, "前端连接服务器"),
    TEXT(1, "文本消息"),
    PICTURE(2, "图片"),
    EMOJI(3, "表情包"),
    CREATE_GROUP(4, "创建群聊"),
    EXIT(10, "断开连接")
    ;

    MessageType(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    @EnumValue
    @JsonValue
    final Integer value;

    final String desc;

    @JsonCreator
    public static MessageType fromValue(int value) {
        for (MessageType type : values()) {
            if (type.value == value) {
                return type;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + value);
    }

}
